using System;
using System.Configuration;

namespace BIUtilities.Publish.CustomConfiguration
{
    /// <summary>
    /// Collection of pas site changes for PPS
    /// </summary>
    public class PerformancePointPasReportSitesElementCollection :
        System.Configuration.ConfigurationElementCollection, IUpdatableConfig
    {

        /// <summary>
        /// Get a pas report site change element
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public PerformancePointPasReportSitesElement this[int index]
        {
            get
            {
                return base.BaseGet(index) as PerformancePointPasReportSitesElement;
            }
            set
            {
                if (base.BaseGet(index) != null)
                {
                    base.BaseRemoveAt(index);
                }
                this.BaseAdd(index, value);
            }
        }

        /// <summary>
        /// Create a new pas report site change element
        /// </summary>
        /// <returns></returns>
        protected override System.Configuration.ConfigurationElement CreateNewElement()
        {
            return new PerformancePointPasReportSitesElement();
        }

        /// <summary>
        /// Get the element's key
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((PerformancePointPasReportSitesElement)element).OriginalPasSite;
        }

        /// <summary>
        /// Makes this element editable
        /// </summary>
        /// <returns></returns>
        public override bool IsReadOnly()
        {
            return false;
        }


        #region IUpdatableConfig Members
        /// <summary>
        /// Creating a public accessor to get at the property values
        /// </summary>
        /// <param name="propertyName"></param>
        /// <returns></returns>
        object IUpdatableConfig.this[string propertyName]
        {
            get { return base[propertyName]; }
            set { base[propertyName] = value; }
        }
        #endregion
    }
}
